﻿Namespace SchoolClick.Security.Providers
    Public Class SchoolClickRoleProvider
        Inherits RoleProvider

        Private DAL As SchoolClickDAL

        Public Sub New()
            DAL = New SchoolClickDAL
        End Sub

        Public Overrides Function RoleExists(roleName As String) As Boolean
            If String.IsNullOrEmpty(roleName.Trim) Then Return False
            Try
                Return DAL.IUsuariosYRoles.RolExist(roleName.Trim)
            Catch ex As Exception
                Return False
            End Try
        End Function

        Public Overrides Function IsUserInRole(username As String, roleName As String) As Boolean
            If String.IsNullOrEmpty(username.Trim) OrElse String.IsNullOrEmpty(roleName.Trim) Then Return False
            Try
                Return DAL.IUsuariosYRoles.IsUser_in_Rol(username.Trim, roleName.Trim)
            Catch ex As Exception
                Return False
            End Try
        End Function

        Public Overrides Function GetRolesForUser(username As String) As String()
            Dim sRol = String.Empty
            If String.IsNullOrEmpty(username.Trim) Then Return New String() {}
            Try
                sRol = DAL.IUsuariosYRoles.GetRoles_For_User(username.Trim)
                Return New String() {sRol}
            Catch ex As Exception
                Return New String() {}
            End Try
            
        End Function

#Region "METODOS NO IMPLEMENTADOS"
        Public Overrides Sub AddUsersToRoles(usernames() As String, roleNames() As String)
            Throw New NotImplementedException
        End Sub

        Public Overrides Property ApplicationName As String
            Get
                Return "SchoolClick® System"
            End Get
            Set(value As String)
                Throw New NotImplementedException
            End Set
        End Property

        Public Overrides Sub CreateRole(roleName As String)
            Throw New NotImplementedException
        End Sub

        Public Overrides Function DeleteRole(roleName As String, throwOnPopulatedRole As Boolean) As Boolean
            Throw New NotImplementedException
        End Function

        Public Overrides Function FindUsersInRole(roleName As String, usernameToMatch As String) As String()
            Throw New NotImplementedException
        End Function

        Public Overrides Function GetAllRoles() As String()
            Throw New NotImplementedException
        End Function

        Public Overrides Function GetUsersInRole(roleName As String) As String()
            Throw New NotImplementedException
        End Function

        Public Overrides Sub RemoveUsersFromRoles(usernames() As String, roleNames() As String)
            Throw New NotImplementedException
        End Sub
#End Region
    End Class
End Namespace